<?php
class BaseController extends Controller{
    public $layout = 'column2';

//    protected $roles = array('MODERATOR', 'ADMIN', 'SUPER_ADMIN');

    function checkAccess(\CWebUser $user, \CAccessRule $rule)
    {
        if($user->isGuest=='true'){
                Yii::app()->user->returnUrl=$_SERVER['REQUEST_URI'];
                $this->redirect($this->createUrl('/user/login'));  
        }
        else{
            $x=User::model()->findByPk($user->id);
            $roles = explode(",", $x->roles);
            $allow = !is_null($x) && ( in_array('MODERATOR', $roles) || in_array('ADMIN', $roles) || in_array('SUPER_ADMIN', $roles));

            return $allow ? FALSE : TRUE; 
        }

    }


   
    public function accessRules()
    {
        return array(
            array(
                'deny',
                'actions'    =>    array(), # all actions
                #'users'        =>    array('?'),
                'expression'=>    array($this, 'checkAccess'),
            )
        );
    }

   
    public function filters()
    {
        return array(
            'accessControl',
        );
    }

    public function actionIndex()
    {
        $this->render('index');
    }

}
?>
